#include "shopunit.h"
#include "custombutton.h"
#include <QPainter>
#include <QLineEdit>
#include <QLabel>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QStyleOption>
#include <QToolButton>

ShopUnit::ShopUnit(QWidget *parent) : QWidget{parent} {

    // 以样式表方式重绘自身
    QString SelfStyleSheet = "background-color: transparent;"
                         "border: 1px solid transparent;"
                         "border-radius: 25px;";
    setStyleSheet(SelfStyleSheet);
    //BSbar->set();
    setFixedSize(360, 132);
    //move(5, 80);

    // contents框
    contents = new QWidget(this);
    QString StyleSheet = "background-color: transparent;"
                         "border: 1px solid lightgray;"
                         "border-radius: 20px;";
    contents->setStyleSheet(StyleSheet);

    contents->setFixedSize(600, 110);


    QVBoxLayout *VLayout = new QVBoxLayout(this);

    // 滑动区域
    ScrollArea = new QScrollArea(this);
    ScrollArea->setFixedSize(350, 132);
    ScrollArea->setWidget(contents);

    this->setLayout(VLayout);
    VLayout->addWidget(ScrollArea);
    VLayout->setAlignment(Qt::AlignTop | Qt::AlignLeft);
    VLayout->setContentsMargins(0, 0, 0, 0);
    // 设置布局管理器的间距为20
    VLayout->setSpacing(5);
    VLayout->addStretch();

    // 店铺名
    QLabel *ShopName = new QLabel(contents);
    //ShopName->setFixedSize(70, 70);
    ShopName->setText("芝士店铺名");
    ShopName->setStyleSheet("border: 1px solid transparent;font-family: 'Microsoft Yahei'; font-size: 18px; font-weight: 700; color: black;");
    ShopName->move(20, 3);
    //HLayout->addWidget(ShopTag);

    //当红炸子鸡
    QLabel *ProductTitle = new QLabel(contents);
    //ProductTitle->setFixedSize(70, 70);
    ProductTitle->setText("当红炸子鸡");
    ProductTitle->setStyleSheet("border: 1px solid transparent;font-family: 'Microsoft Yahei'; font-size: 18px; font-weight: 700; color: black;");
    ProductTitle->move(180, 3);
    //HLayout->addWidget(ShopTag);

    // 店铺图片
    QLabel *ShopImg = new QLabel(contents);
    ShopImg->setFixedSize(70, 70);
    ShopImg->setStyleSheet("border: none; color: black; font-size: 10px; image: url(:/image.png); image-position: top center;");
    // 使用HTML语法来定义图片和文字
    ShopImg->setText("<img src=':/img/res/img/shop.png' width='70' height='70'><div style=></div>"); //'text-align: center;'
    //HLayout->addWidget(ShopImg);
    ShopImg->move(20, 35);

    // 店铺tag
    QLabel *ShopTag = new QLabel(contents);
    ShopTag->setFixedSize(70, 70);
    ShopTag->setText("评分：\n人气：\n特色tag:");
    ShopTag->setStyleSheet("border: 1px solid transparent;font-family: 'Microsoft Yahei'; font-size: 14px; font-weight: 700; color: black;");
    ShopTag->move(95, 35);
    //HLayout->addWidget(ShopTag);


    for(int i = 1; i <= 8; i++) {
//        // 添加商品
//        QPushButton *product1 = new QPushButton(contents);
//        product1->setFixedSize(70, 70);
//        product1->setStyleSheet("border: none; color: black; font-size: 10px; image: url(:/image.png); image-position: top center;");
//        product1->setText("<img src=':/img/res/img/product.png' width='40' height='40'><div style=>芝士商品名<br>芝士评分</div>");
//        product1->move(110 + 80*i, 35);

        // 创建一个工具按钮
        QToolButton *button = new QToolButton(contents);
        // 设置按钮无边框
        button->setStyleSheet("border:none;");
        // 设置按钮上方显示图片
        button->setIcon(QIcon(":/img/res/img/product.png"));
        button->setIconSize(QSize(40, 40));
        // 设置按钮下方显示文字
        button->setText("芝士商品名\n芝士评分");
        button->setFont(QFont("Microsoft YaHei", 8));
        // 设置按钮的图标模式为文本在图标下方
        button->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
        button->setFixedSize(70, 70);
        button->move(110+80*i, 30);

    }
}


void ShopUnit::paintEvent(QPaintEvent *event)
{
    // 启用样式表
    QStyleOption opt;
    opt.initFrom(this);
    QPainter p(this);
    style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);

}



//////商品2
////QLabel *product2 = new QLabel(contents);
////product2->setFixedSize(70, 70);
////product2->setStyleSheet("border: none; color: black; font-size: 10px; image: url(:/image.png); image-position: top center;");
////// 使用HTML语法来定义图片和文字
////product2->setText("<img src=':/img/res/img/product.png' width='40' height='40'><div style=>芝士商品名<br>芝士评分</div>"); //'text-align: center;'
////product2->move(270, 35);

//////商品3
////QLabel *product3 = new QLabel(contents);
////product3->setFixedSize(70, 70);
////product3->setStyleSheet("border: none; color: black; font-size: 10px; image: url(:/image.png); image-position: top center;");
////// 使用HTML语法来定义图片和文字
////product3->setText("<img src=':/img/res/img/product.png' width='40' height='40'><div style=>芝士商品名<br>芝士评分</div>"); //'text-align: center;'
////product3->move(350, 35);

//////商品6
////QLabel *product6 = new QLabel(contents);
////product6->setFixedSize(70, 70);
////product6->setStyleSheet("border: none; color: black; font-size: 10px; image: url(:/image.png); image-position: top center;");
////// 使用HTML语法来定义图片和文字
////product6->setText("<img src=':/img/res/img/product.png' width='40' height='40'><div style=>芝士商品名<br>芝士评分</div>"); //'text-align: center;'
////product6->move(430, 35);

//////商品4
////QLabel *product4 = new QLabel(contents);
////product4->setFixedSize(70, 70);
////product4->setStyleSheet("border: none; color: black; font-size: 10px; image: url(:/image.png); image-position: top center;");
////// 使用HTML语法来定义图片和文字
////product4->setText("<img src=':/img/res/img/product.png' width='40' height='40'><div style=>芝士商品名<br>芝士评分</div>"); //'text-align: center;'
////product4->move(510, 35);

//////商品5
////QLabel *product5 = new QLabel(contents);
////product5->setFixedSize(70, 70);
////product5->setStyleSheet("border: none; color: black; font-size: 10px; image: url(:/image.png); image-position: top center;");
////// 使用HTML语法来定义图片和文字
////product5->setText("<img src=':/img/res/img/product.png' width='40' height='40'><div style=>芝士商品名<br>芝士评分</div>"); //'text-align: center;'
//////product5->move(590, 35);
///



//#include "shopunit.h"
//#include <QPainter>
//#include <QLineEdit>
//#include <QLabel>
//#include <QHBoxLayout>
//#include <QVBoxLayout>
//#include <QStyleOption>

//ShopUnit::ShopUnit(QWidget *parent) : QWidget(parent) {
//    setAutoFillBackground(true);
//    setStyleSheet("background-color: transparent;"
//                  "border: 1px solid lightgray;"
//                  "border-radius: 20px;");
//    setFixedSize(600, 110);

//    //    QVBoxLayout *VLayout = new QVBoxLayout(this);

//    //    // 滑动区域
//    //    ScrollArea = new QScrollArea(this);
//    //    ScrollArea->setFixedSize(350, 132);
//    //    ScrollArea->setWidget(contents);

//    //    this->setLayout(VLayout);
//    //    VLayout->addWidget(ScrollArea);
//    //    VLayout->setAlignment(Qt::AlignTop | Qt::AlignLeft);
//    //    VLayout->setContentsMargins(0, 0, 0, 0);
//    //    // 设置布局管理器的间距为20
//    //    VLayout->setSpacing(5);
//    //    VLayout->addStretch();

//    QVBoxLayout *VLayout = new QVBoxLayout(this);


//    // 滑动区域
//    ScrollArea = new QScrollArea(this);
//    ScrollArea->setFixedSize(350, 132);
//    ScrollArea->setWidgetResizable(true);

//    contents = new QWidget(this);
//    ScrollArea->setWidget(contents);

//    VLayout->addWidget(ScrollArea);
//    VLayout->setAlignment(Qt::AlignTop | Qt::AlignLeft);
//    VLayout->setContentsMargins(0, 0, 0, 0);
//    VLayout->setSpacing(5);
//    VLayout->addStretch();

//    // 店铺名
//    QLabel *ShopName = new QLabel(contents);
//    ShopName->setText("芝士店铺名");
//    ShopName->setStyleSheet("font-family: 'Microsoft Yahei'; font-size: 18px; font-weight: 700; color: black;");
//    ShopName->move(20, 3);

//    // 当红炸子鸡
//    QLabel *ProductTitle = new QLabel(contents);
//    ProductTitle->setText("当红炸子鸡");
//    ProductTitle->setStyleSheet("font-family: 'Microsoft Yahei'; font-size: 18px; font-weight: 700; color: black;");
//    ProductTitle->move(180, 3);

//    // 店铺图片
//    QLabel *ShopImg = new QLabel(contents);
//    ShopImg->setFixedSize(70, 70);
//    ShopImg->setStyleSheet("border: none; color: black; font-size: 10px; image: url(:/image.png); image-position: top center;");
//    ShopImg->setText("<img src=':/img/res/img/shop.png' width='70' height='70'>");
//    ShopImg->move(20, 35);

//    // 店铺tag
//    QLabel *ShopTag = new QLabel(contents);
//    ShopTag->setFixedSize(70, 70);
//    ShopTag->setText("评分：\n人气：\n特色tag:");
//    ShopTag->setStyleSheet("font-family: 'Microsoft Yahei'; font-size: 14px; font-weight: 700; color: black;");
//    ShopTag->move(95, 35);

//    for(int i = 1; i <= 8; i++) {
//        // 添加商品
//        QLabel *product1 = new QLabel(contents);
//        product1->setFixedSize(70, 70);
//        product1->setStyleSheet("border: none; color: black; font-size: 10px; image: url(:/image.png); image-position: top center;");
//        product1->setText("<img src=':/img/res/img/product.png' width='40' height='40'><div style=>芝士商品名<br>芝士评分</div>");
//        product1->move(110 + 80*i, 35);
//    }




//}

//void ShopUnit::paintEvent(QPaintEvent *event)
//{
//    Q_UNUSED(event);

//    QPainter p(this);
//    QStyleOption opt;
//    opt.initFrom(this);
//    style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
//}
